<include file="../header" />

<script type="text/javascript" src="/Template/js/vue.min.js"></script>

<body class="J_scroll_fixed" id="container">
<script type="text/javascript">
    $(function() {

        $("select[name='parentId']").change(function () {
            $("input[name=parentName]").val($("select[name='parentId']").find("option:selected").text());
        });

        $("button.btn_submit").click(function() {
            var codeName = $("input[name=name]").val();
            if(codeName == ""){
                alert("请填写【分类名称】");
                $("input[name=name]").focus();
                return false;
            }

            var parentId = $("select[name=parentId]").val();

            var levelCodeArr=<?php echo json_encode($levelCode);?>;
            var levellist=eval(levelCodeArr);

            for (var i = 0; i < levellist.length; i++) {
                if (parentId == 0 && levellist[i]["code_name"] == codeName && levellist[i]["level"] == 0) {
                    alert("一级分类重名：" + codeName);
                    return false;
                }
                if (parentId != 0 && parentId == levellist[i]["parentid"] && levellist[i]["code_name"] == codeName) {
                    alert("二级分类重名：【" + levellist[i]["parent_name"] + "】" + codeName);
                    return false;
                }
            }

            $("button.btn_submit").hide();

        })


    })

</script>
<div class="wrap jj">
    <div class="common-form">
        <form method="post" class="form-horizontal J_ajaxForm" action="{:U('Code/addPost')}">
            <fieldset>
                <div class="control-group">
                    <label class="control-label">上级分类：</label>
                    <div class="controls">
                        <select name="parentId">
                            {:getCodeSelectOptionHtml($codeId, 1, '0', $user['enterprise_code'])}
                        </select>
                    </div>
                    <input type="hidden" name="parentName" value="">
                </div>
                <div class="control-group">
                    <label class="control-label">分类名称：</label>
                    <div class="controls">
                        <input type="text" class="input" name="name" value="">
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">备注：</label>
                    <div class="controls">
                        <textarea style="height:6rem;" name="remark"></textarea>
                    </div>
                </div>
            </fieldset>
            <div class="form-actions">
                <button type="submit" class="btn btn-primary btn_submit">添加</button>
                <a class="btn" href="__URL__">返回</a>
            </div>
        </form>
    </div>
</div>
<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>